﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Time
{
    public class Time
    {
        private static readonly int MINUTES_PER_HOUR = 60;

        private int allMinutes = 0;
        private int hours = 0;
        private int minutes = 0;

        public int Hours
        {
            get { return this.hours; }
        }
        public int Minutes
        {
            get { return this.minutes; }
        }

        public Time(int hours, int minutes)
        {
            this.allMinutes = hours * MINUTES_PER_HOUR + minutes;
            if (allMinutes < 0)
            {
                throw new Exception("The time cannot be negative.");
            }
            this.hours = allMinutes / MINUTES_PER_HOUR;
            this.minutes = allMinutes % MINUTES_PER_HOUR;
        }

        public static Time operator +(Time time, int minutes)
        {
            return new Time(time.hours, time.minutes + minutes);
        }

        public static Time operator -(Time time, int minutes)
        {
            return new Time(time.hours, time.minutes - minutes);
        }

        public static Time operator --(Time time)
        {
            return new Time(time.hours, time.minutes - 1);
        }

        public static Time operator ++(Time time)
        {
            return new Time(time.hours, time.minutes + 1);
        }

        public override string ToString()
        {
            return String.Format("{0} hours and {1} minutes", this.hours, this.minutes);
        }
    }
}
